/*
 * Filename:    GetFormDateUtil.java
 * Copyright:   2015 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2015-1-21
 */
package com.paic.mhis.hcpms.audit.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.paic.mock.util.StringUtils;

/**
 * 获取日期时间公用类
 * 
 * @author EX-CHENLIN600
 * 
 */

public class GetFormDateUtil {

	/**
	 * 
	 * 日期转字符
	 * 
	 * @param date
	 * @return
	 */
	public static String getStrFromDate(Date date) {
		if (date != null) {
			SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd");
			String value = formate.format(date);
			return value;
		} else {
			return "";
		}

	}

	public static String getStrFromStrByFormat(String dateStr,
			String currentFormate, String targetFormate) {
		String currentStr = "";
		if (StringUtils.hasText(dateStr)) {
			SimpleDateFormat formate = new SimpleDateFormat(currentFormate);
			try {
				Date currentDate = formate.parse(dateStr);

				SimpleDateFormat targetSimpleDateFormat = new SimpleDateFormat(
						targetFormate);
				currentStr = targetSimpleDateFormat.format(currentDate);

			} catch (ParseException e) {
				return dateStr;
			}

		}
		return currentStr;
	}

	public static String getStrFromStr(String dateStr) {
		String currentStr = "";
		if (StringUtils.hasText(dateStr)) {
			SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd");
			try {
				Date currentDate = formate.parse(dateStr);
				currentStr = formate.format(currentDate);

			} catch (ParseException e) {
				e.printStackTrace();
			}

		}
		return currentStr;
	}

	public static String getStrFromDateByModal(String format, Date date) {
		if (date != null) {
			SimpleDateFormat formate = new SimpleDateFormat(format);
			String value = formate.format(date);
			return value;
		} else {
			return "";
		}
	}

}
